<?php
/**
 * Created by IntelliJ IDEA.
 * User: dhy
 * Date: 2015/9/11
 * Time: 15:54
 */

namespace App\Http\Middleware\Customer;
use App\Http\Common\Constant;
use App\Http\Models\Admin\File\FileContent;
use Closure;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Session;
use Illuminate\Support\Facades\Route;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\DB;
class AssetsMiddleware {
    public function handle($request,  $next){

        $ASSETS = array();
        //添加当前路由下需要添加的js和css, 配置项在config/asstes.php. 注意路由转换, 如admin.userinfo 那么在config里面为admin_userinfo
        $addJS = Config::get('assets.'.str_replace(".","_",Route::currentRouteName())."_js");
        $addCSS = Config::get('assets.'.str_replace(".","_",Route::currentRouteName())."_css");
        if($addJS){
            $ASSETS['JS'] =  $addJS;
        };
        if($addCSS){
            $ASSETS['CSS'] =  $addCSS;
        };
       // var_dump(Route::url());
//        $url = request()->route()->getUri();
//        if($url != ""){
//            $pms = explode("/",$url);
//            $find = FileContent::where('name',$pms[0])->where('parent_id',0)->first();
//            $ASSETS['currentCategory'] = $find;
//        }



        $ASSETS['category']=Constant::initCategory();


        //补充footer必需品
//
        $find = DB::select("select t.name,t.title ,s.`name` as parentname from file_content t  left join  file_content s  on
                          t.parent_id = s.id where t.template ='services' and t.parent_id !=0 order by t.show_index asc ");

        $ASSETS['footer_service'] = $find;
//var_dump($find);
        $request['ASSETS'] = $ASSETS;
        return $next($request);
    }


}